local qiongdu = fk.CreateSkill{
  name = "lingling__qiongdu",
}

Fk:loadTranslationTable{
  ["lingling__qiongdu"] = "穷渡",
  [":lingling__qiongdu"] = "每轮各限一次，当你的体力值或手牌数变为0时，若另一项不为1，你可以将之调整至与另一项相同。",

  ["#lingling__qiongdu-hp"] = "穷渡：是否回复体力值至%arg？",
  ["#lingling__qiongdu-hand"] = "穷渡：是否摸%arg张牌？",
}

qiongdu:addEffect(fk.HpChanged, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(qiongdu.name) and
      player.hp == 0 and player:getHandcardNum() > 1 and
      player:usedEffectTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = qiongdu.name,
      prompt = "#lingling__qiongdu-hp:::"..player:getHandcardNum(),
    })
  end,
  on_use = function (self, event, target, player, data)
    player.room:recover{
      who = player,
      num = player:getHandcardNum(),
      recoverBy = player,
      skillName = qiongdu.name,
    }
  end,
})

qiongdu:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qiongdu.name) and player:isKongcheng() and
      player:usedEffectTimes(self.name, Player.HistoryRound) == 0 and
      player.hp > 1 then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = qiongdu.name,
      prompt = "#lingling__qiongdu-hand:::"..player.hp,
    })
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player.hp, qiongdu.name)
  end,
})

return qiongdu
